package com.haowen.service.impl;

import com.haowen.dao.MessageMapper;
import com.haowen.model.Message;
import com.haowen.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MessageServiceImpl implements MessageService {

    @Autowired
    private MessageMapper messageMapper;

    @Override
    public boolean insert(Message message) {
        message.setCreateTime(new Date());
        message.setIsRead(0);  // 默认未读
        return messageMapper.insert(message) > 0;
    }

    @Override
    public List<Message> getReceivedMessages(Integer userId) {
        return messageMapper.selectReceivedMessages(userId);
    }

    @Override
    public List<Message> getSentMessages(Integer userId) {
        return messageMapper.selectSentMessages(userId);
    }

    @Override
    public boolean markAsRead(Integer messageId) {
        return messageMapper.updateReadStatus(messageId, 1) > 0;
    }

    @Override
    public int getUnreadCount(Integer userId) {
        return messageMapper.selectUnreadCount(userId);
    }

    @Override
    public boolean delete(Integer messageId) {
        return messageMapper.delete(messageId) > 0;
    }
} 